﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace G.Controls
{
    public class ChildWindow : Window
    {
        private bool appbarIsVisible;
        protected override void OnOpening()
        {
            base.OnOpening();


            this.Height = this.Page.ActualHeight;
            this.Width = this.Page.ActualWidth;

            if (this.Page.ApplicationBar != null)
            {
                appbarIsVisible = this.Page.ApplicationBar.IsVisible;

                if (appbarIsVisible)
                {
                    this.Page.ApplicationBar.IsVisible = false;
                    this.Height += 72;
                }
            }

            if (Microsoft.Phone.Shell.SystemTray.GetIsVisible(Page))
            {
                this.VerticalOffset = 32;
            }
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            base.OnBackKeyPress(e);
            if (this.IsOpen)
            {
                this.IsOpen = false;
                e.Cancel = true;
            }
        }

        protected override void OnClosed()
        {
            base.OnClosed();
            if (this.Page.ApplicationBar != null)
            {
                if (appbarIsVisible)
                    this.Page.ApplicationBar.IsVisible = true;
            }
        }
    }
}
